package dungeon;

import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.util.ArrayList;

import org.junit.BeforeClass;
import org.junit.Test;

import basicPackage.Direction;
import basicPackage.Temperature;


/**
 * A class collecting tests for the class of normal teleportation squares.
 * 
 * @author 	Frederik Moyaert and Laurens Vanderstraeten
 * 			2de Bach. Burgerlijk Ingenieur, wtkcws
 *
 */
public class NormalTeleportationSquareTest {

	/**
	* Set up an immutable test fixture.
	*
	* @post 	The variable square1Room1 references a new default normal square 
	* 			and borders a wall to the floor and the wall wallRoom1 to the north
	* 		 	and the closed door door1Room1 to the east and the open door door2Room1 to the south.
	* @post 	The variable square2Room1 references a new default normal square 
	* 			and borders a wall to the floor and the wall wallRoom1 to the south.
	* @post 	The variable square3Room1 references a new default normal square 
	* 			and borders a wall to the floor and the closed door door1Room1 to the west.
	* @post 	The variable square1Room2 references a new default normal square 
	* 			and borders a wall to the floor and the square square2Room2 to the north.
	* @post 	The variable square2Room2 references a new default normal square 
	* 			and borders a wall to the floor and the square square1Room2 to the south.
	* @post 	The variable square1Room3 references a new default normal square 
	* 			and borders a wall to the floor and the square tel1Room3 to the north.
	* @post		The variable tel1Room3 references a new default normal teleportation square that borders
	* 			a floor wall and the square square1room3 to the south and has as teleportation destination square1Room1.
	* @post		The variable tel1Room1 references a new default normal teleportation square that borders
	* 			a floor wall and the open door door2Room1 to the north and has as teleportation destination square1Room2.
	* @post		The variable wallRoom1 references a new wall that borders
	* 			two squares: square1Room1 and square2Room1.
	* @post		The variable door1Room1 references a new door that is closed and borders
	* 			two squares: square1Room1 and square3Room1.
	* @post		The variable door2Room1 references a new door that is opened and borders
	* 			two squares: square1Room1 and tel1Room1.
	*/
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		square1Room1 = new NormalSquare();
		square2Room1 = new NormalSquare();
		square3Room1 = new NormalSquare();
		square1Room2 = new NormalSquare();
		square2Room2 = new NormalSquare();
		square1Room3 = new NormalSquare();
		ArrayList<AccessibleSquare> list1 = new ArrayList<AccessibleSquare>();
		list1.add(square1Room1);
		ArrayList<AccessibleSquare> list2 = new ArrayList<AccessibleSquare>();
		list2.add(square1Room2);
		tel1Room3 = new NormalTeleportationSquare(new Temperature(20),new Temperature(-200),new Temperature(5000),BigDecimal.TEN,true,list1);
		tel1Room1 = new NormalTeleportationSquare(new Temperature(20),new Temperature(-200),new Temperature(5000),BigDecimal.TEN,true,list2);
		door1Room1 = new Door();
		door2Room1 = new Door();
		door2Room1.openDoor();
		wallRoom1 = new Wall(true);
		square1Room1.connectToObstacle(Direction.NORTH, wallRoom1);
		square2Room1.connectToObstacle(Direction.SOUTH, wallRoom1);
		square1Room1.connectToObstacle(Direction.EAST, door1Room1);
		square3Room1.connectToObstacle(Direction.WEST, door1Room1);
		square1Room1.connectToObstacle(Direction.SOUTH, door2Room1);
		tel1Room1.connectToObstacle(Direction.NORTH, door2Room1);
		square1Room2.connectToSquare(Direction.NORTH,square2Room2);
		square1Room3.connectToSquare(Direction.NORTH,tel1Room3);
	}
	
	/**
	* Class variables referencing squares that do not
	* change during the entire test case.
	*/
	private static NormalSquare square1Room1,square2Room1,square3Room1, square1Room2,
	square2Room2,square1Room3;
	private static NormalTeleportationSquare tel1Room3,tel1Room1;
	private static Door door1Room1,door2Room1;
	private static Wall wallRoom1;
	
//	/**
//	 * @throws java.lang.Exception
//	 */
//	@Before
//	public void setUp() throws Exception {
//	}

	@Test
	public void isAccessibleFrom_LegalCaseSameRoom() {
		assertTrue(square2Room2.canAccess(square1Room2));
	}
	
	@Test
	public void isAccessibleFrom_LegalCaseOpenDoor() {
		assertTrue(square1Room1.canAccess(tel1Room1));
	}
	
	@Test
	public void isAccessibleFrom_IllegalClosedDoor() {
		assertFalse(square1Room1.canAccess(square3Room1));
	}
	
	@Test
	public void isAccessibleFrom_IllegalWall() {
		assertFalse(square1Room1.canAccess(square2Room1));
	}
	
	@Test
	public void isAccessibleFrom_LegalCaseDirectTeleportation() {
		assertTrue(tel1Room3.canAccess(square1Room1));
	}
	
	@Test
	public void isAccessibleFrom_LegalCaseMoreTeleportations() {
		assertTrue(tel1Room3.canAccess(square2Room2));
	}
	
	@Test
	public void isAccessibleFrom_IllegalWayBack() {
		assertFalse(square1Room1.canAccess(tel1Room3));
	}
	
}
